﻿#region License & Usage

//'Microsoft Public License (Ms-PL) 

//'This license governs use of the accompanying software. If you use the 
//'software, you accept this license. If you do not accept the license, do 
//'not use the software. 

//'1. Definitions 

//'The terms "reproduce," "reproduction," "derivative works," and 
//'"distribution" have the same meaning here as under U.S. copyright law. 

//'A "contribution" is the original software, or any additions or changes 
//'to the software. 

//'A "contributor" is any person that distributes its contribution under 
//'this license. 

//'"Licensed patents" are a contributor's patent claims that read directly 
//'on its contribution. 

//'2. Grant of Rights 

//'(A) Copyright Grant- Subject to the terms of this license, including the 
//'license conditions and limitations in section 3, each contributor grants 
//'you a non-exclusive, worldwide, royalty-free copyright license to 
//'reproduce its contribution, prepare derivative works of its 
//'contribution, and distribute its contribution or any derivative works 
//'that you create. 

//'(B) Patent Grant- Subject to the terms of this license, including the 
//'license conditions and limitations in section 3, each contributor grants 
//'you a non-exclusive, worldwide, royalty-free license under its licensed 
//'patents to make, have made, use, sell, offer for sale, import, and/or 
//'otherwise dispose of its contribution in the software or derivative 
//'works of the contribution in the software. 

//'3. Conditions and Limitations 

//'(A) No Trademark License- This license does not grant you rights to use 
//'any contributors' name, logo, or trademarks. 

//'(B) If you bring a patent claim against any contributor over patents 
//'that you claim are infringed by the software, your patent license from 
//'such contributor to the software ends automatically. 

//'(C) If you distribute any portion of the software, you must retain all 
//'copyright, patent, trademark, and attribution notices that are present 
//'in the software. 

//'(D) If you distribute any portion of the software in source code form, 
//'you may do so only under this license by including a complete copy of 
//'this license with your distribution. If you distribute any portion of 
//'the software in compiled or object code form, you may only do so under a 
//'license that complies with this license. 

//'(E) The software is licensed "as-is." You bear the risk of using it. The 
//'contributors give no express warranties, guarantees or conditions. You 
//'may have additional consumer rights under your local laws which this 
//'license cannot change. To the extent permitted under your local laws, 
//'the contributors exclude the implied warranties of merchantability, 
//'fitness for a particular purpose and non-infringement.

#endregion

#region Options

//

#endregion

#region Imports

//From .Net Framework 3.5
using Microsoft.Drawing;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Reflection;
using System.Windows.Forms;

//From Custom Classes/Reference
using StedySoft.SenseSDK;
using StedySoft.SenseSDK.DrawingCE;
using SenseSDKExtended;
using SenseSDKExtended.DrawingCEEx;

#endregion

namespace SenseSDKExtendedDemoCSharp
{
    public partial class frm_SensePanelHistogram_Style1 : Form
    {

        #region "Fields"

        //General Images from Resources folder
        IImage icon_search = SenseAPIs.SenseImage.LoadIImageFromFile(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(0, System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.LastIndexOf("\\")) + "\\Resources\\" + (Resolution.ScreenIsVGA ? "SearchButton.VGA" : "SearchButton.QVGA") + ".png");
        IImage icon_arrow_right = SenseAPIs.SenseImage.LoadIImageFromFile(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(0, System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.LastIndexOf("\\")) + "\\Resources\\" + (Resolution.ScreenIsVGA ? "HTCArrowStyle1.Right.Gray.VGA" : "HTCArrowStyle1.Right.Gray.QVGA") + ".png");
        IImage icon_greenhacks_logo = SenseAPIs.SenseImage.LoadIImageFromFile(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(0, System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.LastIndexOf("\\")) + "\\Resources\\" + (Resolution.ScreenIsVGA ? "Greenhacks.Logo.VGA" : "Greenhacks.Logo.QVGA") + ".png");
        IImage icon_contact = SenseAPIs.SenseImage.LoadIImageFromFile(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(0, System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.LastIndexOf("\\")) + "\\Resources\\" + (Resolution.ScreenIsVGA ? "contact_vga" : "contact_qvga") + ".png");
        IImage icon_exit = SenseAPIs.SenseImage.LoadIImageFromFile(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(0, System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.LastIndexOf("\\")) + "\\Resources\\" + (Resolution.ScreenIsVGA ? "ExitButton.VGA" : "ExitButton.QVGA") + ".png");
        IImage icon_addnew = SenseAPIs.SenseImage.LoadIImageFromFile(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(0, System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.LastIndexOf("\\")) + "\\Resources\\" + (Resolution.ScreenIsVGA ? "AddNewButton.VGA" : "AddNewButton.QVGA") + ".png");
        IImage icon_addressbook = SenseAPIs.SenseImage.LoadIImageFromFile(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(0, System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.LastIndexOf("\\")) + "\\Resources\\" + (Resolution.ScreenIsVGA ? "AddressBookButton.VGA" : "AddressBookButton.QVGA") + ".png");
        IImage icon_map = SenseAPIs.SenseImage.LoadIImageFromFile(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(0, System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.LastIndexOf("\\")) + "\\Resources\\" + (Resolution.ScreenIsVGA ? "MapButton.VGA" : "MapButton.QVGA") + ".png");

        //Declare header control to add on top of the form
        private SenseHeaderControl s_header = new SenseHeaderControl();

        //Declare list control to add below the header control on the form
        private SenseListControl s_list = new SenseListControl();

        //Declare sensepanel item for information
        private SenseSDKExtended.SensePanelItemEx.HTCContactsStyle4 s_panelitemex = new SenseSDKExtended.SensePanelItemEx.HTCContactsStyle4();
        private SenseSDKExtended.SensePanelHistogram.Style1 s_panelhistogram = new SenseSDKExtended.SensePanelHistogram.Style1();

        //Save Histogram file name/path if we want to save generated graph
        private String s_panelhistogram_filepath = null;

        #endregion

        #region Methods

        private bool _isVGA()
        {
            return Resolution.ScreenIsVGA;
        }

        public frm_SensePanelHistogram_Style1()
        {
            InitializeComponent();
        }

        private void frm_SensePanelHistogram_Style1_Closed(object sender, System.EventArgs e)
        {
            //Dispose list control and header control
            s_list.Dispose();
            s_header.Dispose();
        }

        private void frm_SensePanelHistogram_Style1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //Clear the list control
            s_list.Clear();
        }

        private void frm_SensePanelHistogram_Style1_Load(object sender, EventArgs e)
        {

            //Create header control properties
            s_header.Dock = System.Windows.Forms.DockStyle.Top;
            s_header.Location = new System.Drawing.Point(0, 0);
            s_header.Name = "s_header";
            s_header.Size = new System.Drawing.Size(240, 25);
            s_header.TabIndex = 0;
            s_header.Text = "SenseSDK Extended Demo";

            switch (this.Tag.ToString())
            {

                case "btn_frm_SensePanelHistogram_Style1_1":

                    //s_panelhistogram.BackColor = Color.White;

                    s_panelhistogram.Title.Caption = "Facebook Friends Messages Graph";
                    s_panelhistogram.Title.Font = new Font("Tahoma", 8, FontStyle.Regular);

                    s_panelhistogram.Height = 500;

                    s_panelhistogram.XAxisTitle.Caption = "Months (2010)";
                    s_panelhistogram.XAxisTitle.Font = new Font("Tahoma", 6, FontStyle.Regular | FontStyle.Bold);
                    s_panelhistogram.XAxisTitle.FontColor = Color.Maroon;
                    s_panelhistogram.XAxisMinimum = 0;
                    s_panelhistogram.XAxisMaximum = 12;
                    s_panelhistogram.XAxisInterval = 1;

                    s_panelhistogram.YAxisTitle.Caption = "Messages Received";
                    s_panelhistogram.YAxisTitle.Font = new Font("Tahoma", 6, FontStyle.Regular | FontStyle.Bold);
                    s_panelhistogram.YAxisTitle.FontColor = Color.Maroon;
                    s_panelhistogram.YAxisMinimum = 0;
                    s_panelhistogram.YAxisMaximum = 500;
                    s_panelhistogram.YAxisInterval = 50;

                    s_panelhistogram.LayerStyle = SenseSDKExtended.SensePanelHistogram.Style1.HistogramLayerStyle.HorizontalStripe;

                    s_panelhistogram.Data.Add(0, 1, 100, Color.FromArgb(200, 255, 50),-1);
                    s_panelhistogram.Data.Add(1, 1, 75, Color.FromArgb(150, 240, 0), -1);
                    s_panelhistogram.Data.Add(2, 1, 18, Color.FromArgb(150, 230, 0), -1);
                    s_panelhistogram.Data.Add(3, 1, 359, Color.FromArgb(150, 210, 0), -1);
                    s_panelhistogram.Data.Add(4, 1, 210, Color.FromArgb(150, 190, 0), -1);
                    s_panelhistogram.Data.Add(5, 1, 491, Color.FromArgb(150, 170, 0), -1);
                    s_panelhistogram.Data.Add(6, 1, 40, Color.FromArgb(150, 150, 0), -1);
                    s_panelhistogram.Data.Add(7, 1, 360, Color.FromArgb(150, 130, 0), -1);

                    s_panelhistogram.SaveFileAllow = true;
                    s_panelhistogram.OnFileGenerated += new SenseSDKExtended.SensePanelHistogram.Style1.OnFileGeneratedEventHandler(s_panelhistogram_OnFileGenerated);
                    
                    s_panelitemex.PrimaryText = "Sense Histogram Control - Also has option to save the graph.";
                    s_panelitemex.Name = "s_panelitemex";
                    s_panelitemex.iThumbnailLeft = icon_arrow_right;
                    s_panelitemex.PropertyTable = SenseSDKExtended.SensePanelItemEx.HTCContactsStyle4Options.ProcessProperties(s_panelitemex);

                    break;

            }

            //Create list control properties.
            s_list.Dock = System.Windows.Forms.DockStyle.Fill;
            s_list.IsSecondaryScrollType = false;
            s_list.Location = new System.Drawing.Point(0, 200);
            s_list.MinimumMovement = 15;
            s_list.Name = "s_list";
            s_list.ShowScrollIndicator = false;
            s_list.TabIndex = 1;
            s_list.ThreadSleep = 100;
            s_list.TopIndex = 0;
            s_list.Velocity = 0.9f;
            s_list.Springback = 0.35f;

            //Add list control first on the form
            this.Controls.Add(s_list);

            //Add header control second on the form
            this.Controls.Add(s_header);

            //Sense list control beginupdates
            s_list.BeginUpdate();

            //Add s_panelhistogram style to list control
            s_list.AddItem(s_panelhistogram);

            //Add a seperator
            s_list.AddItem(new SensePanelDividerItem("sep", "Description"));

            //Add sensepanel to list control
            s_list.AddItem(s_panelitemex);

            //Add button to list control
            SensePanelButtonItem btb_close = new SensePanelButtonItem();
            btb_close.Text = "Back";
            btb_close.OnClick += new SensePanelButtonItem.ClickEventHandler(btb_close_OnClick);
            s_list.AddItem(btb_close);

            //End updates of sense list control
            s_list.EndUpdate();
        }

        private void s_panelhistogram_OnFileGenerated(object sender, string filepath)
        {
            s_panelhistogram_filepath = filepath;

        }

        private void btb_close_OnClick(object sender)
        {

            //Save this file somewhere now
            MessageBox.Show(s_panelhistogram_filepath, "Path", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);

            //Close form
            this.Close();
        }


        #endregion

    }
}